<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2005/12/05 22:12:34 $)
// $RCSfile: staff_tags.php,v $ : $Revision: 1.9 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

if ($_SWIFT["staff"]["ls_entab"] == "0")
{
	echo '<font face="Verdana, Arial, Helvetica" size="2" color="red"><b>'.$_SWIFT["language"]["nopermission"].'</b></font>';
	exit;
}

require_once ("./includes/functions_html.php");
$grid = new Grid();

$interface->assignQuickLink($_SWIFT["language"]["htmlbutton"], "index.php?_m=livesupport&_a=htmlbutton", "icon_htmlcode.gif");
$interface->assignQuickLink($_SWIFT["language"]["emailsignature"], "index.php?_m=livesupport&_a=emailbutton", "icon_emailsignature.gif");
$interface->assignQuickLink($_SWIFT["language"]["textlink"], "index.php?_m=livesupport&_a=textlink", "icon_textlink.gif");


/**
* ###############################################
* HTML BUTTON
* ###############################################
*/
if ($eventaction == "htmlbutton")
{
	if ($_POST["update"] == "1" && $_POST["departmentid"] != "")
	{
		$departmentid = $_POST["departmentid"];
		$infomessage = $_SWIFT["language"]["generatedcode"];
	} else {
		$departmentid = "0";
	}

	$htmlcode .= '<!-- Begin '. SWIFTPRODUCT .' Javascript Code -->'.SWIFT_CRLF;
	$htmlcode .= '<script language="javascript" src="'. $_SWIFT["swiftpath"] .'visitor/index.php?_m=livesupport&_a=htmlcode&departmentid='. $departmentid .'"></script>'.SWIFT_CRLF;
	$htmlcode .= '<!-- End '. SWIFTPRODUCT .' Javascript Code -->'.SWIFT_CRLF;

	$interface->staffHeader($_SWIFT["language"]["taggenerator"], 3);

	$interface->staffNavBar('<a href="index.php?_m=livesupport&_a=htmlbutton" title="'.$_SWIFT["language"]["htmlbutton"].'">'.$_SWIFT["language"]["htmlbutton"]."</a>", "", 3);

	printInfoBox($infomessage);
	printErrorBox($errormessage);

	printFormStart();
	printMainTableHeader($_SWIFT["language"]["htmlbutton"]);

	printDescRow($_SWIFT["language"]["htmlcode"]);
	printTextareaRow("statushtmlcode", $_SWIFT["language"]["htmlcode"], $_SWIFT["language"]["desc_htmlcode"], $htmlcode, "60", "6", false);

	$options[0]["title"] = $_SWIFT["language"]["alldepartments"];
	$options[0]["value"] = "0";
	$index = 1;
	foreach ($_SWIFT["departmentcache"] as $key=>$val)
	{
		if ($val["departmentmodule"] == MODULE_LIVESUPPORT)
		{
			$options[$index]["title"] = $val["title"];
			$options[$index]["value"] = $val["departmentid"];
			$index++;
		}
	}

	printDescRow($_SWIFT["language"]["customsettings"]);
	printSelectRow("departmentid", $_SWIFT["language"]["fordepartment"], $_SWIFT["language"]["desc_fordepartment"], $options);

	printSubmitRow($_SWIFT["language"]["generate"]);

	printMainTableFooter();

	addHiddenField("_m", "livesupport");
	addHiddenField("_a", "htmlbutton");
	addHiddenField("update", "1");
	printFormEnd();

	$interface->staffFooter();


/**
* ###############################################
* EMAIL BUTTON
* ###############################################
*/
} else if ($eventaction == "emailbutton") {
	if ($_POST["update"] == "1" && $_POST["departmentid"] != "")
	{
		$departmentid = $_POST["departmentid"];
		$infomessage = $_SWIFT["language"]["generatedcode"];
	} else {
		$departmentid = "0";
	}

	$htmlcode .= '<a href="'. $_SWIFT["swiftpath"] .'visitor/index.php?_m=livesupport&_a=emailchat&departmentid='. $departmentid .'"><img src="'. $_SWIFT["swiftpath"] .'visitor/index.php?_m=livesupport&_a=emailimage&departmentid='. $departmentid .'" border="0" /></a>'.SWIFT_CRLF;

	$interface->staffHeader($_SWIFT["language"]["taggenerator"], 3);

	$interface->staffNavBar('<a href="index.php?_m=livesupport&_a=emailbutton" title="'.$_SWIFT["language"]["emailsignature"].'">'.$_SWIFT["language"]["emailsignature"]."</a>", "", 3);
	
	printInfoBox($infomessage);
	printErrorBox($errormessage);

	printFormStart();
	printMainTableHeader($_SWIFT["language"]["emailsignature"]);

	printDescRow($_SWIFT["language"]["htmlcode"]);
	printTextareaRow("statushtmlcode", $_SWIFT["language"]["htmlcode"], $_SWIFT["language"]["desc_htmlcode"], $htmlcode, "60", "6", false);

	$options[0]["title"] = $_SWIFT["language"]["alldepartments"];
	$options[0]["value"] = "0";
	$index = 1;
	foreach ($_SWIFT["departmentcache"] as $key=>$val)
	{
		if ($val["departmentmodule"] == MODULE_LIVESUPPORT)
		{
			$options[$index]["title"] = $val["title"];
			$options[$index]["value"] = $val["departmentid"];
			$index++;			
		}
	}

	printDescRow($_SWIFT["language"]["customsettings"]);
	printSelectRow("departmentid", $_SWIFT["language"]["fordepartment"], $_SWIFT["language"]["desc_fordepartment"], $options);

	printSubmitRow($_SWIFT["language"]["generate"]);

	printMainTableFooter();

	addHiddenField("_m", "livesupport");
	addHiddenField("_a", "emailbutton");
	addHiddenField("update", "1");
	printFormEnd();

	$interface->staffFooter();
	


/**
* ###############################################
* TEXT LINK
* ###############################################
*/
} else if ($eventaction == "textlink") {
	if ($_POST["update"] == "1" && trim($_POST["departmentid"]) != "" && trim($_POST["onlinetext"]) != "" && trim($_POST["offlinetext"]) != "")
	{
		$departmentid = $_POST["departmentid"];
		$infomessage = $_SWIFT["language"]["generatedcode"];
		$custom = base64_encode(serialize(array($_POST["onlinetext"], $_POST["offlinetext"])));
		$htmlcode .= '<!-- Begin '. SWIFTPRODUCT .' Javascript Code -->'.SWIFT_CRLF;
		$htmlcode .= '<script language="javascript" src="'. $_SWIFT["swiftpath"] .'visitor/index.php?_m=livesupport&_a=htmlcode&departmentid='. $departmentid .'&custom='.urlencode($custom).'"></script>'.SWIFT_CRLF;
		$htmlcode .= '<!-- End '. SWIFTPRODUCT .' Javascript Code -->'.SWIFT_CRLF;
	} else if ($_POST["update"] == 1) {
		$errormessage = $_SWIFT["language"]["requiredfieldempty"];
	}

	$interface->staffHeader($_SWIFT["language"]["taggenerator"], 3);

	$interface->staffNavBar('<a href="index.php?_m=livesupport&_a=textlink" title="'.$_SWIFT["language"]["textlink"].'">'.$_SWIFT["language"]["textlink"]."</a>", "", 3);

	printInfoBox($infomessage);
	printErrorBox($errormessage);

	printFormStart();
	printMainTableHeader($_SWIFT["language"]["textlink"]);

	if (!empty($htmlcode))
	{
		printDescRow($_SWIFT["language"]["htmlcode"]);
		printTextareaRow("statushtmlcode", $_SWIFT["language"]["htmlcode"], $_SWIFT["language"]["desc_htmlcode"], $htmlcode, "60", "6", false);
	}

	printDescRow($_SWIFT["language"]["customsettings"]);

	$options[0]["title"] = $_SWIFT["language"]["alldepartments"];
	$options[0]["value"] = "0";
	$index = 1;
	foreach ($_SWIFT["departmentcache"] as $key=>$val)
	{
		if ($val["departmentmodule"] == MODULE_LIVESUPPORT)
		{
			$options[$index]["title"] = $val["title"];
			$options[$index]["value"] = $val["departmentid"];
			$index++;
		}
	}

	printSelectRow("departmentid", $_SWIFT["language"]["fordepartment"], $_SWIFT["language"]["desc_fordepartment"], $options);
	printTextareaRow("onlinetext", $_SWIFT["language"]["onlinetext"], $_SWIFT["language"]["desc_onlinetext"], iif(!empty($_POST["onlinetext"]), $_POST["onlinetext"], $_SWIFT["language"]["conlinetext"]), "60", "3");
	printTextareaRow("offlinetext", $_SWIFT["language"]["offlinetext"], $_SWIFT["language"]["desc_offlinetext"], iif(!empty($_POST["offlinetext"]), $_POST["offlinetext"], $_SWIFT["language"]["cofflinetext"]), "60", "3");
	
	printSubmitRow($_SWIFT["language"]["generate"]);

	printMainTableFooter();

	addHiddenField("_m", "livesupport");
	addHiddenField("_a", "textlink");
	addHiddenField("update", "1");
	printFormEnd();

	$interface->staffFooter();


/**
* ###############################################
* VISITOR TRACKING LINK
* ###############################################
*/
} else if ($eventaction == "visitortracking") {
	if ($_POST["update"] == "1" && trim($_POST["departmentid"]) != "")
	{
		$departmentid = $_POST["departmentid"];
		$infomessage = $_SWIFT["language"]["generatedcode"];
		$custom = base64_encode(serialize(array("&nbsp;", "&nbsp;")));
		$htmlcode .= '<!-- Begin '. SWIFTPRODUCT .' Javascript Code -->'.SWIFT_CRLF;
		$htmlcode .= '<script language="javascript" src="'. $_SWIFT["swiftpath"] .'visitor/index.php?_m=livesupport&_a=htmlcode&nolink=1&departmentid='. $departmentid.'"></script>'.SWIFT_CRLF;
		$htmlcode .= '<!-- End '. SWIFTPRODUCT .' Javascript Code -->'.SWIFT_CRLF;
	} else if ($_POST["update"] == 1) {
		$errormessage = $_SWIFT["language"]["requiredfieldempty"];
	}

	$interface->staffHeader($_SWIFT["language"]["taggenerator"], 3);

	$interface->staffNavBar('<a href="index.php?_m=livesupport&_a=visitortracking" title="'.$_SWIFT["language"]["visitortracking"].'">'.$_SWIFT["language"]["visitortracking"]."</a>", "", 3);

	printInfoBox($infomessage);
	printErrorBox($errormessage);

	printFormStart();
	printMainTableHeader($_SWIFT["language"]["visitortracking"]);

	if (!empty($htmlcode))
	{
		printDescRow($_SWIFT["language"]["htmlcode"]);
		printTextareaRow("statushtmlcode", $_SWIFT["language"]["htmlcode"], $_SWIFT["language"]["desc_htmlcode"], $htmlcode, "60", "6", false);
	}

	printDescRow($_SWIFT["language"]["customsettings"]);

	$options[0]["title"] = $_SWIFT["language"]["alldepartments"];
	$options[0]["value"] = "0";
	$index = 1;
	foreach ($_SWIFT["departmentcache"] as $key=>$val)
	{
		if ($val["departmentmodule"] == MODULE_LIVESUPPORT)
		{
			$options[$index]["title"] = $val["title"];
			$options[$index]["value"] = $val["departmentid"];
			$index++;
		}
	}

	printSelectRow("departmentid", $_SWIFT["language"]["fordepartment"], $_SWIFT["language"]["desc_fordepartment"], $options);
	
	printSubmitRow($_SWIFT["language"]["generate"]);

	printMainTableFooter();

	addHiddenField("_m", "livesupport");
	addHiddenField("_a", "visitortracking");
	addHiddenField("update", "1");
	printFormEnd();

	$interface->staffFooter();
}


?>